package com.example.compose.state

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ElevatedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.compose.ui.theme.CustomTheme


@Composable
fun BasicMutableState() {
    val flag = remember { mutableStateOf(false) }
    ElevatedButton(onClick = { flag.value = !flag.value }) {
        Text(
            text = if (flag.value) "yes" else "no",
            fontSize = 36.sp
        )
    }
}

@Composable
fun By() {
    var flag by remember { mutableStateOf(false) }
    ElevatedButton(onClick = { flag = !flag }) {
        Text(
            text = if (flag) "yes" else "no",
            fontSize = 36.sp
        )
    }
}

@Composable
fun RememberSaveable() {
    var flag by rememberSaveable { mutableStateOf(false) }
    ElevatedButton(onClick = { flag = !flag }) {
        Text(
            text = if (flag) "yes" else "no",
            fontSize = 36.sp
        )
    }
}

@Preview
@Composable
fun Exps() {
    CustomTheme {
        Column(
            modifier = Modifier.padding(48.dp)
        ) {
            BasicMutableState()

            By()

            RememberSaveable()
        }
    }
}

